﻿using iTextSharp.text;
using iTextSharp.text.pdf;

namespace TianYu.Core.Pdf.ContentElement.Text
{
    public abstract class AbstractTextElement : AbstractElement
    {
        /// <summary> 背景色：1白色， 2黑色 </summary>
        public int BackgroundColor { get; set; }

        /// <summary> 文字： 1白色， 2黑色 </summary>
        public int FontColor { get; set; }

        /// <summary> 边框 </summary>
        public BorderModel Border { get; set; }

        protected void DrawRectangle(ColumnText columnText, PdfContentByte pdfContentByte, int topDifference)
        {
            //画矩形 第一个矩形用作边框 
            var rectBorder = new Rectangle(X, Y, X + Width, Y + Height);

            //边框
            var reduce = CommonHelper.LineWidthReduce;
            rectBorder.BorderWidthLeft = Border.WidthLeft / reduce;
            rectBorder.BorderWidthRight = Border.WidthRight / reduce;
            rectBorder.BorderWidthBottom = Border.WidthBottom / reduce;
            rectBorder.BorderWidthTop = Border.WidthTop / reduce;

            if (BackgroundColor > 1)
            {
                rectBorder.BackgroundColor = CommonHelper.GetBaseColor(BackgroundColor);
            }

            pdfContentByte.Rectangle(rectBorder);
            columnText.SetSimpleColumn(rectBorder);

            //第二用于控制内边距离
            var rectTemp = new Rectangle(X + Border.PaddingLeft, Y + Border.PaddingBottom, X + Width - Border.PaddingRight, Y + Height - Border.PaddingTop - topDifference);

            if (BackgroundColor > 1)
            {
                rectTemp.BackgroundColor = CommonHelper.GetBaseColor(BackgroundColor);
            }

            pdfContentByte.Rectangle(rectTemp);
            columnText.SetSimpleColumn(rectTemp);
        }
    }
}
